package top.jsjkxyjs.blackbox.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jsjkxyjs.blackbox.entity.Iot;
import top.jsjkxyjs.blackbox.mapper.IotMapper;
import top.jsjkxyjs.blackbox.service.IotService;
import top.jsjkxyjs.blackbox.utils.Utils;

import java.util.*;

@Service
public class IotServiceImpl implements IotService {
	@Autowired
	IotMapper iotMapper;


	@Override
	public Map getUserIotDataLimit(int devId, String type) {
		List<Iot> userIotDataLimit = iotMapper.getUserIotDataLimit(devId, type);
		Collections.reverse(userIotDataLimit);
		HashMap data = new HashMap<>();
		List<String> value = new ArrayList<>();
		List<String> time = new ArrayList<>();
		for (Iot iot : userIotDataLimit) {
			value.add(iot.getValue());
			time.add(Utils.getDateString(iot.getAt()));
		}
		data.put("type", type);
		data.put("value", value);
		data.put("time", time);
		return data;
	}

	@Override
	public boolean getIotDevCase(int devId) {
		return iotMapper.getIotDevCase(devId) > 0 && iotMapper.getIotBindCase(devId) == 0;
	}

	@Override
	public Iot getIotInfo() {
		return iotMapper.getIotInfo();
	}

	@Override
	public boolean setIotState(Iot iot) {
		return iotMapper.setIotState(iot) > 0;
	}

	@Override
	public int getiotsDatasNumber() {

		return iotMapper.getiotsDatasNumber();
	}
}
